package com.halko.PR.service.impl;

import static org.bytedeco.javacpp.opencv_highgui.imread;
import org.bytedeco.javacpp.opencv_core.*;

import com.halko.PR.pr.chars.CharsRecognition;
import com.halko.PR.pr.detect.PlateDetection;
import com.halko.PR.service.PlateRecognise;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/**
 * @author halko
 * @create 2021-04-11 18:57
 */
@Service
public class PlateRecogniseImpl implements PlateRecognise {
    @Override
    public List<String> plateRecognise(String imgPath) {
        List<String> result=new ArrayList<String>();
        Mat src = imread(imgPath);
        PlateDetection pd = new PlateDetection();
        CharsRecognition cr = new CharsRecognition();
        pd.setPDDebug(true);
        cr.setCRDebug(true);
        // 车牌方块集合
        Vector<Mat> plateVec = new Vector<Mat>();
        if (pd.plateDetect(src, plateVec) == 0) {
            for (int i = 0; i < plateVec.size(); ++i) {
                result.add(cr.charsRecognition(plateVec.get(i)));
            }
        }
        return result;
    }
}
